package com.sss.springboot.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.sss.springboot.mapper.UserMapper;
import com.sss.springboot.model.User;
import com.sss.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Component
@Service(interfaceClass = UserService.class)
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Override
    public Map<String, Object> findAll() {
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        String loginAct = (String) redisTemplate.opsForValue().get("loginAct");
        String loginPwd = (String) redisTemplate.boundValueOps("loginPwd").get();
        HashMap<String, Object> map = new HashMap<>();
        map.put("loginAct", loginAct);
        map.put("loginPwd", loginPwd);

        return map;
    }

    @Override
    public User updateById(String id, User user) {
        return null;
    }


    @Override
    public User update(User user) {
        userMapper.updateByPrimaryKeySelective(user);
        return user;
    }

    @Override
    public User select(String id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> findUser() {
        return userMapper.findUser();
    }


}
